
import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import edu.towson.cosc603.coffeemaker.Inventory;
import edu.towson.cosc603.coffeemaker.Recipe;

public class InventoryTest extends TestCase {

	Inventory inventory;
	@Before
	public void setUp() throws Exception {
		inventory = new Inventory();
		//Checking the constructor.
		assertEquals(15,inventory.getChocolate());
		assertEquals(15,inventory.getCoffee());
		assertEquals(15,inventory.getMilk());
		assertEquals(15,inventory.getSugar());
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testSetChocolate() {
		//Testing negative amount.
		inventory.setChocolate(-3);
		assertEquals(0, inventory.getChocolate());
		//Testing valid/positive data.
		inventory.setChocolate(3);
		assertEquals(3,inventory.getChocolate());
	}

	@Test
	public void testSetCoffee() {
		//Testing negative data.
		inventory.setCoffee(-3);
		assertEquals(0, inventory.getCoffee());
		//Testing valid/positive data.
		inventory.setCoffee(3);
		assertEquals(3,inventory.getCoffee());
	}

	@Test
	public void testSetMilk() {
		//Testing negative data.
		inventory.setMilk(-3);
		assertEquals(0, inventory.getMilk());
		//Testing valid/positive data.
		inventory.setMilk(3);
		assertEquals(3,inventory.getMilk());
	}

	@Test
	public void testSetSugar() {
		//Testing negative data.
		inventory.setSugar(-3);
		assertEquals(0, inventory.getSugar());
		//Testing positive/valid data.
		inventory.setSugar(3);
		assertEquals(3,inventory.getSugar());
	}

	@Test
	public void testEnoughIngredients() {
		//Checking valid inventory.
		Recipe r = new Recipe();
		r.setAmtChocolate(3);
		r.setAmtCoffee(3);
		r.setAmtMilk(3);
		r.setAmtSugar(3);
		Inventory valid = new Inventory();
		assertTrue(valid.enoughIngredients(r));
		
		//Checking Invalid conditions.
		r.setAmtChocolate(16);
		assertFalse(valid.enoughIngredients(r));
		r.setAmtChocolate(2);
		//Invalid condition
		r.setAmtCoffee(16);
		assertFalse(valid.enoughIngredients(r));
		r.setAmtCoffee(2);
		//Invalid condition
		r.setAmtMilk(16);
		assertFalse(valid.enoughIngredients(r));
		r.setAmtMilk(2);
		//Invalid condition.
		r.setAmtSugar(16);
		assertFalse(valid.enoughIngredients(r));
	}

	@Test
	public void testToString() {
		Inventory i = new Inventory();
		String result = "Coffee: 15\nMilk: 15\nSugar: 15\nChocolate: 15\n";
		assertEquals (result , i.toString());
	}

}
